// import Common from "../Common";
import SDKEvent from "./SDKEvent";

export default class BaseSDK {
    protected _isRecorder: boolean = false;
    protected _payOptions: any;
    protected _shareOptions: any;
    protected _loginOptions: any;

    protected init() {

    }

    login(options) {
        options.success && options.success({
            isLogin: true
        });
    }
    isOpenShare() {
        return true;
    }

    getAnonymousCode(): string {
        return "";
    }

    createMoreGamesButton(options) {

    }

    setKeepScreenOn(options) {

    }

    setClipboardData(options) {
        console.log("调用剪切板", options.data);
    }

    startRecorder() {
        this._isRecorder = true;
        console.log("开始录屏");
        cc.systemEvent.emit(SDKEvent.CHANGE_RECORDER_STATE);
    }

    stopRecorder(shareFunc) {
        this._isRecorder = false;
        console.log("停止录屏")
        cc.systemEvent.emit(SDKEvent.CHANGE_RECORDER_STATE);
    }

    getRecorderState() {
        return this._isRecorder;
    }

    getIsScreenRecordVideo() {
        return true;
    }
    getRecorderTime() {
        return 0;
    }
    showShareBtn(type: number) {

    }
    hideShareBtn() {

    }
    shareRecorder(options) {
        options.success && options.success();
        console.log("分享视频成功");
    }

    showRewardVideo(options) {
        options && options.success && options.success();
        console.log("展示广告成功");
    }

    playScreen() {
        console.log("播放插屏广告");
    }
    getLastAdTime() {
        return 0;
    }
    showBanner() {

    }
    hideBanner() {

    }

    getVideoState() {
        return true;
    }
    onVideoSuccess() {

    }

    vibrateShort() {
        // console.log("短震动");
    }

    vibrateLong() {
        // console.log("长震动");
    }
    sendEvent(event) {
        console.log("打点:", event);
    }

    postMessage(data) {
        console.log("推送消息", data);
    }

    setLocalStorage(key, value) {
        cc.sys.localStorage.setItem(key, value);
    }

    getLocalStorage(key) {
        console.log("获取本地数据");
        return cc.sys.localStorage.getItem(key);
    }

    sendHttpRequest(url, data, turnBack, failBack) {
        let keys = Object.getOwnPropertyNames(data);
        let params = "";
        for (let i = 0; i < keys.length; i++) {
            console.log("参数名称：", keys[i]);
            params += keys[i] + "=" + data[keys[i]] + "&"
        }
        console.log("请求参数", params);
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    if (turnBack) {
                        var result = JSON.parse(xhr.responseText);
                        if (result.ok) {
                            turnBack(result);
                        } else {
                            if (failBack) {
                                failBack(result.msg);
                            }
                        }
                    }
                } else {
                    if (failBack) {
                        failBack(xhr.status);
                    }
                }
            }
        };
        xhr.open("POST", url, true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send(params);
    }
    showToast(content) {
        console.log("showToast", content);
    }

    getOpenDataContext() {
        return null;
    }

    loginWithDouyin() {

    }
    loginWithApple() {

    }

    dyTokenSuccess(token, openId) {

    }
    appleLoginSuccess(code, nickName) {

    }
    loginError() {

    }
    hasAppleLogin() {
        return true;
    }

    share(options) {

    }
    contentSafe(options) {
        let data = { text: options.content, platform: options.platform };
        // this.sendHttpRequest(Common.contentSafeAll,data,(res)=>{
        //     if(res.valid){
        //         options.callBack(true);
        //     }else{
        //         options.callBack(false);
        //     }
        // },(res)=>{
        //     options.callBack(false);
        // })
    }

}